//
// Created by 123 on 2024/3/9.
//串
#include <iostream>

using namespace std;

#define MAXLEN 20
typedef struct {
    char ch[MAXLEN];
    int length;
} SString;

SString init(){
    SString s;
    s.length=0;
    return s;
}

//赋值操作
void strAssign(SString &t, char ch[]);

//复制操作
void stringCopy(SString &t, SString s);

//判空操作
bool isEmpty(SString s);

//比较操作
int strCompare(SString s, SString t);

//求串长
int strLength(SString t);

//求子串
bool subString(SString &sub, SString s,int pos, int len);


//串连接
SString concat(SString s1, SString s2);

//定位操作
int indexof(SString s, SString t);

//清空操作
void clearString(SString &s);

//销毁
void destroString(SString &s);

void show(SString  s){
    for (int i = 1; i <= s.length; ++i) {
        cout<<s.ch[i]<<"   ";
    }
    cout<<endl;
}
void show_char(char a[],int len){
    for (int i = 0; i < len; ++i) {
        cout<<a[i]<<"   ";
    }
    cout<<endl;
}




int main() {

    SString  str1=init();
    str1.ch[1]='1';
    str1.ch[2]='2';
    str1.ch[3]='3';
    str1.ch[4]='4';
    str1.ch[5]='5';
    str1.length=5;
    SString  str2=init();
    str2.ch[1]='6';
    str2.ch[2]='7';
    str2.ch[3]='8';
    str2.ch[4]='9';
    str2.ch[5]='*';
    str2.length=5;


    char ch[MAXLEN];

    strAssign(str1,ch);
    show_char(ch,str1.length);

    show(str1);

    cout<<"-------------------------------"<<endl;
    SString s=init();
    stringCopy(s,str1);
    show(s);

    SString s1=init();
    cout<<isEmpty(s1)<<"     <---------"<<endl;
    cout<<isEmpty(s)<<"     <---------"<<endl;

    s.ch[5]='5';









}

//赋值操作
void strAssign(SString &t, char ch[]){
    for (int i = 0; i < t.length; ++i) {
        ch[i]=t.ch[i+1];
    }

}

//复制操作
void stringCopy(SString &t, SString s){
    for (int i = 1; i <= s.length; ++i) {
        t.ch[i]=s.ch[i];
    }
    t.length=s.length;
}

//判空操作
bool isEmpty(SString s){
    return s.length==0;
}

//比较操作
int strCompare(SString s, SString t){
    int i=1;
    while (i<=t.length&&i<=s.length){
        if(t.ch[i]!=s.ch[i]){
            return s.ch[i]-t.ch[i]>0?1:-1;
        }
        i++;
    }
    return s.length-t.length>0?1:-1;
}

//求串长
int strLength(SString t){
    return t.length;
}

//求子串
bool subString(SString &sub, SString s,int pos, int len){
    if(len>(s.length-pos+1)){
        return false;
    }
    int j=1;
    for (int i = pos; i <pos+ len; ++i) {
        sub.ch[j]=s.ch[i];
        j++;
    }
    sub.length=len;
    return true;
}

//串连接
SString concat(SString s1, SString s2){
    SString ans;
    for (int i = 1; i <= s1.length; ++i) {
        ans.ch[i]=s1.ch[i];
    }
    int in=s1.length+1;
    for (int i = 1; i <= s2.length; ++i) {
        ans.ch[in]=s2.ch[i];
        in++;
    }
    ans.length=s1.length+s2.length;
    return ans;
}

//定位操作
int indexof(SString s, SString t){
    int i=1;
    int j=1;
    while (i<=s.length&&j<=t.length){
        if(s.ch[i]==t.ch[j]){
            i++;
            j++;
        }else{
            i=i-j+2;
            j=1;
        }
    }
    if(j>t.length){
        return i-t.length;
    }else{
        return 0;
    }

}

//清空操作
void clearString(SString &s){

}

//销毁
void destroString(SString &s);